package com.leyou.controller;

import com.leyou.dto.Order;
import com.leyou.dto.OrderFormDto;
import com.leyou.entity.OrderDTO;
import com.leyou.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author jshstart
 * @creat 2020-12-26 17:00
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PostMapping
    public ResponseEntity<Long> submitOrder(@RequestBody @Valid OrderFormDto orderFormDto){
       Long orderId=orderService.submitOrder(orderFormDto);
        System.out.println("orderId = " + orderId);
       return ResponseEntity.ok(orderId);
    }
    @GetMapping("/{id}")
    public ResponseEntity<OrderDTO> queryOrderById(@PathVariable("id") Long id){
        Order order = orderService.getById(id);
        OrderDTO orderDTO = new OrderDTO(order);
        return ResponseEntity.ok(orderDTO);
    }

}
